using System.Collections.Generic;
using Firestarter.Test.Base;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.BO;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    ///Unique constraint must have property
    /// </summary>
    [TestFixture]
    public class TestDMUniqueConstraintRules
    {
        [SetUp]
        public void SetupTest()
        {
            //Runs every time that any testmethod is executed
            TestUtilsDomain.SetupTest();
            BORegistry.DataAccessor = new DataAccessorInMemory();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            //Code that is executed before any test is run in this class. If multiple tests
            // are executed then it will still only be called once.
            TestUtilsDomain.SetupFixture();
        }

        [TearDown]
        public void TearDownTest()
        {
            //runs every time any testmethod is complete
        }

        #region DMUniqueConstraintRules

        [Test]
        public void Test_HasWarnings_WhenNoUniqueProperty_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMUniqueConstraint uniqueConstraint = TestUtilsShared.CreateUnsavedValidUniqueConstraintInfo();
            //---------------Assert Precondition----------------
            string msg;
            Assert.IsTrue(uniqueConstraint.Status.IsValid(out msg), "Err Msg : " + msg);
            Assert.AreEqual(0 , uniqueConstraint.UniqueConstraintProperties.Count);
            //---------------Execute Test ----------------------
            IList<IBOError> errors;
            bool hasWarnings = uniqueConstraint.Status.HasWarnings(out errors);
            //---------------Test Result -----------------------
            Assert.IsTrue(hasWarnings);
            Assert.AreEqual(1, errors.Count);
            StringAssert.Contains("must have at least one Property", errors[0].Message);
        }

        [Test]
        public void Test_HasWarnings_WhenAllSetUp_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMUniqueConstraintProperty constraintPropertyInfo = TestUtilsShared.CreateUnsavedValidUniqueConstraintPropertyInfo();
            DMUniqueConstraint uniqueConstraint = constraintPropertyInfo.UniqueConstraint;
            //---------------Assert Precondition----------------
            string msg;
            Assert.IsTrue(uniqueConstraint.Status.IsValid(out msg), "Err Msg : " + msg);
            Assert.AreEqual(1, uniqueConstraint.UniqueConstraintProperties.Count);
            //---------------Execute Test ----------------------
            IList<IBOError> errors;
            bool hasWarnings = uniqueConstraint.Status.HasWarnings(out errors);
            //---------------Test Result -----------------------
            Assert.IsFalse(hasWarnings);
            Assert.AreEqual(0, errors.Count);
        }

        #endregion
    }
}